package com.billion.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 定义机组rabbit队列对应关系
 */
@Configuration
public class WattConfig {

    /**
     * 声明电表交换机
     * @return
     */
    @Bean
    public static DirectExchange wattExchange() {
        return new DirectExchange("watt_exchange");
    }

    /**
     * 声明4G电表队列
     *
     * @return
     */
    @Bean
    public Queue jobWatt4GQueue(){
        return new Queue("job_watt_4G_queue");
    }

    /**
     * 声明NB电表队列
     *
     * @return
     */
    @Bean
    public Queue jobWattNBQueue(){
        return new Queue("job_watt_NB_queue");
    }

    /**
     * 声明AEP电表队列
     *
     * @return
     */
    @Bean
    public Queue jobWattAEPQueue(){
        return new Queue("job_watt_AEP_queue");
    }

    /**
     * 声明4G电表抄表返回队列
     *
     * @return
     */
    @Bean
    public Queue resultWatt4GQueue(){
        return new Queue("result_watt_4G_queue");
    }

    /**
     * 声明NB电表抄表返回队列
     *
     * @return
     */
    @Bean
    public Queue resultWattNBQueue(){
        return new Queue("result_watt_NB_queue");
    }

    /**
     * 声明AEP电表抄表返回队列
     *
     * @return
     */
    @Bean
    public Queue resultWattAEPQueue(){
        return new Queue("result_watt_AEP_queue");
    }

    /**
     * 将4G电表抄表队列绑定路由
     * @return
     */
    @Bean
    public Binding jobWatt4GDirectBindExchange() {
        return BindingBuilder.bind(jobWatt4GQueue()).to(wattExchange()).with("job_4G");
    }

    /**
     * 将NB电表抄表队列绑定路由
     * @return
     */
    @Bean
    public Binding jobWattNBDirectBindExchange() {
        return BindingBuilder.bind(jobWattNBQueue()).to(wattExchange()).with("job_NB");
    }

    /**
     * 将AEP电表抄表队列绑定路由
     * @return
     */
    @Bean
    public Binding jobWattAEPDirectBindExchange() {
        return BindingBuilder.bind(jobWattAEPQueue()).to(wattExchange()).with("job_AEP");
    }

    /**
     * 将4G电表抄表结果绑定路由
     * @return
     */
    @Bean
    public Binding resultWatt4GDirectBindExchange() {
        return BindingBuilder.bind(resultWatt4GQueue()).to(wattExchange()).with("result_4G");
    }

    /**
     * 将NB电表抄表结果绑定路由
     * @return
     */
    @Bean
    public Binding resultWattNBDirectBindExchange() {
        return BindingBuilder.bind(resultWattNBQueue()).to(wattExchange()).with("result_NB");
    }

    /**
     * 将AEP电表抄表结果绑定路由
     * @return
     */
    @Bean
    public Binding resultWattAEPDirectBindExchange() {
        return BindingBuilder.bind(resultWattAEPQueue()).to(wattExchange()).with("result_AEP");
    }
}